import org.junit.jupiter.api.Test;

import java.util.ArrayDeque;
import java.util.Queue;

public class test1417 {
    public String reformat(String s) {
        Queue<Character> letters = new ArrayDeque<>();
        Queue<Character> numbers = new ArrayDeque<>();
        for(int i = 0; i < s.length(); ++i){
            char cur = s.charAt(i);
            if(Character.isLetter(cur)){
                letters.add(cur);
            }else{
                numbers.add(cur);
            }
        }
        if(Math.abs(letters.size() - numbers.size()) > 1){
            return "";
        }
        else if(letters.size() > numbers.size()){
            StringBuffer temp = new StringBuffer();
            while(!numbers.isEmpty()){
                temp.append(letters.poll());
                temp.append(numbers.poll());
            }
            temp.append(letters.poll());
            return temp.toString();
        }else{
            StringBuffer temp = new StringBuffer();
            while(!letters.isEmpty()){
                temp.append(numbers.poll());
                temp.append(letters.poll());
            }
            if(!numbers.isEmpty()){
                temp.append(numbers.poll());
            }
            return temp.toString();
        }
    }

    @Test
    public void test(){
        String res = reformat("ab123");
        System.out.println("res = " + res);
    }
}
